<#include "${ftl_skin}/common/header.ftl">


<style type="text/css">
    .ztree li span.button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle}
</style>


</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">业务机构</div>
        <div class="ibox-content">


            <div class="row">
                <div class="col-xs-3">
                    <div id="treeDiv" class='ztree'></div>
                </div>
                <div class="col-xs-9" id="rightDiv">
                    <!--工具条按钮-->
                    <div class="btn-group">

                        <button type="button" class="btn btn-info" onClick="javascript:choice();return false;">选用</button>

                        <button type="button" class="btn btn-info" onClick="javascript:cancel();return false;">取消</button>

                       

                    </div>
                    <!--工具条按钮 END-->

                    <br />

                   
                </div>
            </div>


        </div><!-- end ibox-content -->
    </div><!-- end ibox -->
</div><!-- end wrap -->



<#include "${ftl_skin}/common/js.ftl">




<script type="text/javascript" src="${path.commonPath }tools/yxTree/yx.yxTree.js?1=1"></script>


<link rel="stylesheet" href="${path.commonPath }tools/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${path.commonPath }tools/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="${path.commonPath }tools/zTree_v3/js/jquery.ztree.exedit-3.5.js"></script>

<script type="text/javascript">
    var tree = new yxTree('tree');

    $(function(){

        $.ajax({
            url: "${path.servicePath}/busiunit/treelist.do",
            async: false,
            type: 'POST',
            data: {parent_tree_code:'${parentSeqCode}'},
            complete:function(XMLHttpRequest, textStatus){
//                 alert(XMLHttpRequest.responseText);
            },
            success: function(data){
                if(data.state == 0){
                    var msg = data.result;

                    for(var i in msg){
              //           alert(msg[i].PARENT_TREE_CODE + '_' + msg[i].TREE_CODE);
               	//		alert(msg[i].ID);
                        tree.nodes[msg[i].PARENT_TREE_CODE + '_' + msg[i].TREE_CODE] = 'text:' + msg[i].NODE_NAME + ';treeid:' + msg[i].ID + ';url:' + msg[i].URL + ';';
                    }
//                    tree.toString('treeDiv');
                    //输出 json 格式
                    var treeNodes = tree.toArr();
                    var json = [];

                    treeToJson(json, treeNodes[0].childNodes);

                  //  alert(JSON.stringify(json));
                    initZTree(json);
                }
            }
        });

        winSizeEvent(loadWinSize); // 窗口自动调整
    });


    // 控制页面布局 ( 根据浏览器可视面积动态改变 宽高度 )
    function loadWinSize(){

        // 控制页面布局 ( 根据浏览器可视面积动态改变 宽高度 )
        $('#treesetiframe').height($(window).height() - 180);
        $('#treesetiframe').width($('#rightDiv').width());


    }



    //把数组转换成 json
    function treeToJson(json, treeNodeArr){
        for(var i = 0; i < treeNodeArr.length; i++){
            var tmpJson = {};
            tmpJson.id = treeNodeArr[i].sourceId;
            tmpJson.name = treeNodeArr[i].text;
            tmpJson.treeid=treeNodeArr[i].treeid;
            // tmpJson.url = treeNodeArr[i].url;
            tmpJson.target = 'treesetiframe';
            tmpJson.open = true;
            if(treeNodeArr[i].hasChild){
                tmpJson.isParent = true;
                tmpJson.children = [];
                treeToJson(tmpJson.children, treeNodeArr[i].childNodes);
            }
            json.push(tmpJson);
        }
    }

    function initZTree(json){

        var setting = {
            view: {
                selectedMulti: false
            },
            edit: {
                enable: false,  //手工打开编辑模式
                editNameSelectAll: false,
                showRemoveBtn: false,
                showRenameBtn: false
            },
            data: {
                simpleData: {
                    enable:true,
                    idKey: "id",
                    pIdKey: "pId",
                    rootPId: ""
                }
            },
            callback: {
                beforeClick: function(treeId, treeNode) {
                //     alert(treeNode.name + ":" + treeNode.id+":"+treeNode.treeid);
                    $('#' + treeId).attr('nodeName', treeNode.name).attr('nodeId', treeNode.id).attr('nodeTreeId',treeNode.treeid);

                },



            }
        };

        var zTree = $.fn.zTree.init($("#treeDiv"), setting, json);
    }



 


   
    

    //===========================按钮操作================================//

    //确定
    function choice(){
        //返回name,id参数
        //关闭dialog
        if(isSet($('#treeDiv').attr('nodeId'))){
        
		var returnVal={
		nodeId:$('#treeDiv').attr('nodeTreeId'),
		nodeName:$('#treeDiv').attr('nodeName')
		};
		
		closeDialog(returnVal);
        }else{
        alert("请先选择结点！");
        }
    }
    
 	 //取消
    function cancel(){
     	//关闭dialog
     	var returnVal={
		nodeId:"",
		nodeName:""
		};
    	closeDialog(returnVal);
    }
   

  
</script>

<#include "${ftl_skin}/common/footer.ftl">
